package com.boat.starter.ruoyi.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.boat.starter.ruoyi.client.RedisClient;
import com.boat.starter.ruoyi.client.RuoyiClient;
import com.boat.starter.ruoyi.config.props.AdmAuthConsts;
import com.boat.starter.ruoyi.config.props.AuthProperties;
import com.boat.starter.ruoyi.filter.TokenAuthFilter;
import com.boat.starter.ruoyi.listener.SyncConfigRunner;
import com.boat.starter.ruoyi.service.AdmAuthService;

import lombok.extern.slf4j.Slf4j;

/**
 * rms自动装配,用于统一声明bean、拦截器等
 * 
 * @author 周江
 *
 */
@Slf4j
@Configuration
@EnableScheduling
@EnableConfigurationProperties(AuthProperties.class)
@ConditionalOnProperty(prefix = AdmAuthConsts.PREFIX, value = "type", havingValue = AdmAuthConsts.AuthType.RUOYI)
public class RuoyiAutoConfiguration implements InitializingBean {

	@Override
	public void afterPropertiesSet() throws Exception {
		log.info("boat-starter-ruoyi加载成功");
	}

	@Bean
	public RuoyiClient ruoyiClient(AuthProperties authProperties) {
		return new RuoyiClient(authProperties);
	}

	@Bean
	public RedisClient redisClient(AuthProperties authProperties) {
		return new RedisClient(authProperties);
	}

	@Bean
	public AdmAuthService ruoyiService(AuthProperties authProperties) {
		return new AdmAuthService(authProperties);
	}

	@Bean
	public TokenAuthFilter tokenAuthFilter(AuthProperties authProperties) {
		return new TokenAuthFilter();
	}

	@Bean
	public SyncConfigRunner syncConfigRunner(AuthProperties authProperties) {
		return new SyncConfigRunner(authProperties);
	}

}
